home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Programmer Disk
/
The Programmer Disk (Microforum).iso
/
xpro
/
c3
/
pro19
/
text_win.asm
< prev
next >
Wrap
Assembly Source File
|
1992-11-03
|
5KB
|
203 lines
_gettextimage proto far C, row1:SWORD, col1:SWORD, row2:SWORD, col2:SWORD
_puttextimage proto far C ,
row1:SWORD, col1:SWORD, row2:SWORD, col2:SWORD, buffer:WORD
IFNDEF ENOMEM
ENOMEM EQU 12
ENDIF
.model large, C
.286
.code
;* This procedure should be the counterpart for textmodes
;* to the QuickC - library function _getimage function for graphic modes;
;* use _puttextimage function listed below for restoring.
;* unsigned int _gettextimage (short row1, short col1,
;* short row2, short col2)
;* _gettextimage: expecting: - absolute coordinates (row, column) of specified
;* screen region in textmode
;*
;* returns:
;* - address of memory where region is saved
;* (paragraph)
_gettextimage proc far C ,
row1:SWORD, col1:SWORD, row2:SWORD, col2:SWORD
LOCAL rows:WORD, cols:WORD, buffer:WORD
mov ah, 0Fh
int 10h ; get video mode
.IF (al >= 4 && al <= 6) || (al >= 0dh)
mov ax, 0 ; if graphic mode
jmp @exit ; return (with optional code in AX)
.ENDIF
.IF al == 7 || !al ; if monochrome
mov buffer, 0b000h
.ELSE ; else VGA
mov buffer, 0b800h
.ENDIF ; 'buffer' = video buffer
push ax
mov ax, 1000h
shr bx, 8 ; BX = video page
mul bx
add buffer, ax ; get address of current page
pop ax
mov rows, 25 ; suppose 25 rows for simplicity
; (normal text mode)
shr ax, 8 ; AH = number of textcolumns
mov cols, ax
mov ax, col2
sub ax, col1
add ax, 1
mov dx, row2
sub dx, row1
add dx, 1 ; compute n° of words needed to
mul dx ; store screen region
shr ax, 2
add ax, 1 ; paragraphs needed
mov bx, ax
mov ah, 48h
int 21h ; allocate memory
jnc @F
mov ax, ENOMEM
jmp @exit
@@: push ax
mov ax, 2
int 33h ; turn mouse off
pop es ; ES = allocated memory
push ds
xor di, di
mov ax, buffer ; fit DS:SI
mov ds, ax
mov ax, es
mov buffer, ax ; buffer: now memory block
mov ax, row1
dec ax
mov bx, col1
dec bx ; get coordinates
.REPEAT
.REPEAT
push ax
push bx
mov bx, cols
mul bx ; AX = row * col
pop bx
add ax, bx ; AX = (row * col) + col
mov si, ax
shl si, 1 ; TWO words/screen position
mov ax, word ptr ds:[si]
mov word ptr es:[di], ax ; save
add di, 2
inc bx ; col = col + 1
pop ax
.UNTIL bx > col2
inc ax ; row = row + 1
mov bx, col1
dec bx
.UNTIL ax > row2
pop ds ; restore DS
mov ax, 1
int 33h ; turn mouse on
mov ax, buffer ; return memory address
@exit: ret
_gettextimage endp
;** The next procedure restores the previously saved text screen image;
;** it expects the coordinates where to locate it an the address of the
;** memory block where it is saved. The allocated memory is then freed.
;* int _puttextimage (short row1, short col1,
;* short row2, short col2, unsigned int buffer);
_puttextimage proc far C ,
row1:SWORD, col1:SWORD, row2:SWORD, col2:SWORD, buffer:WORD
LOCAL cols:WORD
push es
mov ax, 2 ; turn mouse off
int 33h
mov ah, 0Fh
int 10h ; get video mode
push ax
.IF al == 7 || !al
mov ax, 0b000h
.ELSE
mov ax, 0b800h
.ENDIF
mov es, ax
mov ax, 1000h
shr bx, 8
mul bx
mov bx, es
add bx, ax
mov es, bx ; get address of current page
pop ax
shr ax, 8 ; AH = number of textcolumns
mov cols, ax
push ds
mov ax, buffer
mov ds, ax
xor si, si ; fit DS:SI
mov ax, row1
dec ax
mov bx, col1
dec bx
.REPEAT
.REPEAT
push ax
push bx
mov bx, cols
mul bx ; AX = row * col
pop bx
add ax, bx ; AX = (row * col) + col
mov di, ax
shl di, 1 ; TWO words/screen position
mov ax, word ptr ds:[si]
mov word ptr es:[di], ax ; write to screen
add si, 2
inc bx ; col = col + 1
pop ax
.UNTIL bx > col2
inc ax ; row = row + 1
mov bx, col1
dec bx
.UNTIL ax > row2
pop ds
mov ax, buffer
mov es, ax
mov ah, 49h
int 21h ; free allocated memory
jnc @exit
mov ax, ENOMEM ; on error return ENOMEM
jmp @F
@exit: mov ax, 0 ; if successful return 0
@@: push ax
mov ax, 1 ; turn mouse cursor on
int 33h
pop ax
pop es
ret
_puttextimage endp
end